package com.mhy.netspeedutils;

import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.mhy.netspeed.HyNetSpeedUtils;

/**
 * =====================================
 * 作    者：mahongyin
 * 项    目：HYNetSpeedUtils
 * 目    录：com.mhy.hynetspeedutils
 * 创建日期：2024/8/22 上午9:47
 * 描    述：
 * 使    用：
 * =====================================
 */
public class MainActivity extends AppCompatActivity {

    private TextView downloadSpeedTextView;
    private TextView uploadSpeedTextView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        downloadSpeedTextView = findViewById(R.id.downloadSpeedTextView);
        uploadSpeedTextView = findViewById(R.id.uploadSpeedTextView);

        HyNetSpeedUtils.getInstance().start(1000, new HyNetSpeedUtils.OnNetSpeedListener() {
            @Override
            public void onDownSpeed(long mSpeed) {
                Log.i("down speed:", "" + mSpeed);
                downloadSpeedTextView.setText("Download Speed:" + mSpeed + " B/s");
            }

            @Override
            public void onUpSpeed(long mSpeed) {
                Log.i("up speed:", "" + mSpeed);
                uploadSpeedTextView.setText("Upload Speed:" + mSpeed + " B/s");
            }
        });

    }

    @Override
    protected void onResume() {
        super.onResume();
        HyNetSpeedUtils.getInstance().resume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        HyNetSpeedUtils.getInstance().pause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        HyNetSpeedUtils.getInstance().stop();
    }
}
